package se.zens.demo.wsapp.implementation.customers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.Response;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import se.zens.demo.wsapp.configuration.WSAppConfiguration;
import se.zens.demo.wsapp.implementation.AbstractWSAppProcessor;
import se.zens.demo.wsapp.interfaces.model.Customer;
import se.zens.demo.wsapp.interfaces.model.CustomerList;

public class GetAllCustomerProcessor extends AbstractWSAppProcessor<Customer>
{ 
	private static Logger logger = LogManager.getLogger(GetAllCustomerProcessor.class);
	private Response response ;
	private Map<String, Customer> customers;
	private WSAppConfiguration config;
	
	

	public GetAllCustomerProcessor(WSAppConfiguration config,
			Map<String, Customer> customers)
	{
		this.config = config;
		this.customers = customers;
		this.config = config;
	}

	@Override
	public void process()
	{
		
		if( customers == null || customers.isEmpty())
		{
			response = Response.noContent().build();
			return ;
		}
		
		List<Customer> list = new ArrayList<Customer>(customers.values());
		response = Response.ok(new CustomerList(list)).build();
		
	}
	
	public Response getResponse()
	{
		return response;
	}
}
